<template>
	<Layout class="p-5 bg-white">
		<Form :label-width="150">
			<Row>

				<Col span="8">
				<!-- <FormItem class="w-100" label="车名">
					<input v-model="car.name" />
				</FormItem> -->
				<FormItem class="w-100" label="车龄">
					<Input v-model="car.carCondition" />
				</FormItem>
				<FormItem class="w-100" label="表显里程">
					<Input v-model="car.mileage" />
				</FormItem>
				<!-- <FormItem class="w-100" label="排量">
					<input v-model="car.displacement" />
				</FormItem> -->
				<FormItem class="w-100" label="车牌归属">
					<Input v-model="car.ownerShip" />
				</FormItem>
				<!-- <FormItem class="w-100" label="颜色">
					<Input v-model="car.color" />
				</FormItem> -->
				
				<FormItem class="w-100" label="车主姓名">
					<Input v-model="car.personName" />
				</FormItem>
				</Col>


				<Col span="8">
					<FormItem class="w-100" label="价格">
						<Input v-model="car.rentalPrice" />
					</FormItem>
				<FormItem class="w-100" label="型号">
					<Input v-model="car.type" />
				</FormItem>
				<!-- <FormItem class="w-100" label="排放标准">
					<Select v-model="car.standard" style="width:160px">
						<Option v-for="item in paifangList" :value="item.value">{{ item.label }}</Option>
					</Select>
				</FormItem>
				<FormItem class="w-100" label="座数">
					<input v-model="car.seats" />
				</FormItem>
				<FormItem class="w-100" label="燃油类型">
					<Select v-model="car.energy" style="width:160px">
						<Option v-for="item in ranyouList" :value="item.value">{{ item.label }}</Option>
					</Select>
				</FormItem>
				<FormItem class="w-100" label="驱动类型">
					<Select v-model="car.drive" style="width:160px">
						<Option v-for="item in qudongList" :value="item.value">{{ item.label }}</Option>
					</Select>
				</FormItem> -->
				<!-- <FormItem class="w-100" label="出场日期">
					<el-date-picker v-model="car.productionDate" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"
						placeholder="请选择时间">
					</el-date-picker>
				</FormItem> -->
				</FormItem>
				<!-- <FormItem class="w-100" label="国别">
					<input v-model="car.country" />
				</FormItem> -->
				<FormItem class="w-100" label="车主电话">
					<Input v-model="car.tel" />
					
				</FormItem>
				<FormItem class="w-100" label="车主微信">
					<Input v-model="car.wxNumber" />
					
				</FormItem>
				
				<FormItem class="w-100" label="图片上传">
					<div v-if="car.imgUrl != ''">
					  <img
					    :src="car.imgUrl"
					    style="width:180px;height:120px"
					  />
					  <div class="demo-upload-list-cover">
					    <Icon
					      type="ios-trash-outline"
					      @click.native="handleRemove"
					    ></Icon>
					  </div>
					</div>
					<Upload
					  with-credentials
					  :max-size="2048"
					  :show-upload-list="false"
					  name="file"
					  ref="upload"
					  :format="['jpg', 'jpeg', 'png']"
					  :data="{ module: 'car', date: new Date() }"
					  :on-format-error="handleFormatError"
					  :on-exceeded-size="handleMaxSize"
					  :on-success="handleSuccess"
					  :action="url"
					>
					  <Button icon="ios-cloud-upload-outline" style="margin-top: 5px"
					    >Upload files</Button
					  >
					</Upload>
				</FormItem> 
				<FormItem class="w-100" label="多图片上传">
					<div v-if="imgUrlList != ''" v-for="(item,index) in imgUrlList" :key="index">
					  <img
					    :src="imgUrlList[index].imgUrl"
					    style="width:180px;height:120px;display: inline-block;"
					  />
					  <div class="demo-upload-list-cover">
					    <Icon
					      type="ios-trash-outline"
					      @click.native="handleListRemove()"
					    ></Icon>
						
					  </div>
					</div>
					<Upload
					  with-credentials
					  :max-size="2048"
					  :show-upload-list="false"
					  name="file"
					  ref="upload"
					  multiple
					  type="drag"
					  :format="['jpg', 'jpeg', 'png']"
					  :data="{ module: 'car', date: new Date() }"
					  :on-format-error="handleFormatError"
					  :on-exceeded-size="handleMaxSize"
					  :on-success="handleListSuccess"
					  :action="url"
					   style="display: inline-block;width:58px;"
					>
					  <div style="width: 58px;height:58px;line-height: 58px;">
					              <Icon type="ios-camera" size="20"></Icon>
					          </div>
					</Upload>
				</FormItem>
				<FormItem class="text-right">
					<Button @click="submit" type="primary">提交</Button>
					<Button @click="cancel" class="ml-2">取消</Button>
				</FormItem>
				</Col>
			</Row>
		</Form>
	</Layout>
</template>

<script>
	export default {
		data: function() {
			return {
				url:'',
				iport:'',
				imgUrlList:[],
				imgList:[],
				img:'',
				imgs:'',
				carId: 1,
				car: {},
				styleList: [{
						value: '三厢车',
						label: '三厢车'
					},
					{
						value: '两厢车',
						label: '两厢车'
					},
					{
						value: 'SUV',
						label: 'SUV'
					},
					{
						value: '掀背车',
						label: '掀背车'
					},
					{
						value: '跑车',
						label: '跑车'
					},
					{
						value: 'MPV',
						label: 'MPV'
					},
					{
						value: '敞篷车',
						label: '敞篷车'
					},
					{
						value: '旅行车',
						label: '旅行车'
					},
					{
						value: '皮卡',
						label: '皮卡'
					},
					{
						value: '客车',
						label: '客车'
					},
					{
						value: '货车',
						label: '货车'
					}
				],
				paifangList: [{
						value: '国四',
						label: '国四'
					},
					{
						value: '国五',
						label: '国五'
					},
					{
						value: '国六',
						label: '国六'
					},
					{
						value: '国六B',
						label: '国六B'
					}

				],
				ranyouList: [{
						value: '汽油',
						label: '汽油'
					},
					{
						value: '柴油',
						label: '柴油'
					},
					{
						value: '电动',
						label: '电动'
					},
					{
						value: '油电混合',
						label: '油电混合'
					},
					{
						value: '其它',
						label: '其它'
					}
				],
				qudongList: [{
						value: '前驱',
						label: '前驱'
					},
					{
						value: '后驱',
						label: '后驱'
					},
					{
						value: '四驱',
						label: '四驱'
					}
				]

			};
		},
		methods: {
			//图片上传时文件格式错误方法
			handleFormatError(file) {
			  this.$Notice.warning({
			    title: '文件格式不正确',
			    desc:
			      '文件 ' +
			      file.name +
			      ' 格式不正确，请上传 jpg 或 png 或 jpeg格式的图片。',
			  })
			},
			//校验图片的大小，不能大于2M
			handleMaxSize: function(file) {
			  this.$Modal.info({
			    title: '超出文件大小限制',
			    content: '文件 ' + file.name + ' 太大，不能超过 2M。',
			  })
			},
			handleRemove(file) {
			  // 从 upload 实例删除数据 
			  this.$data.carSellClientVo.imgUrl = ''
			},
			//上传成功后的勾子 
			handleSuccess: function(response, file, fileList) {
				
			  this.$data.carSellClientVo.imgUrl = response.DATA.URL
			  console.log( this.$data.carSellClientVo.imgUrl)
			},
			
			handleListRemove(file) {
			  // 从 upload 实例删除数据 
			  this.$data.imgUrlList = []
			},
			//上传成功后的勾子 
			handleListSuccess: function(response, file, fileList) {
				this.$data.imgs = response.DATA.URL
			  var img = {}
			  img.carId = this.$data.carId
			  img.imgUrl = this.$data.imgs
			  console.log(img)
			  this.$data.imgUrlList.unshift(img)
			  
			  // this.$data.imgUrlList.carId = this.$data.car.carId
			  // this.$data.imgUrlList.imgUrl = response.DATA.URL
			  console.log( this.$data.imgUrlList)
			},
			
			
			
			cancel: function() {

				this.$tabs.close();
			},
			submit: function() {
				let self = this;
				
				if (this.$data.car.mileage.length == 0) {

					this.message.error("里程必须输入");
					return;
				}

				this.http.put({
					url: "/car-rental-info/info",
					param: self.car,
				}).then(() => {
					self.message.info("修改成功");
					self.$tabs.close();
					this.$router.push({
						name: "carRental",
						params: {}
					})
				});
			},
			init: function() {


				let self = this;
				console.log(self.$data.carId)
				self.http.get({
					url: "/car-rental-info/info",
					param: {
						carId: self.$data.carId
					}
				}).then(data => {

					self.$data.car = data;
					console.log(self.$data.car)
				});



			}
		},
		created: function() {
			this.$data.carId = this.$route.params.carId;
			this.init();
		},
	}
</script>

<style>
</style>
